(function ($) {
	var preData = {}
	var keys = {},statusKey=''
	var pageArr=[],icon="",titleStr="";
	var method = '',pageType = '',perInfo={}
	var TomcatUrl = JSON.parse(localStorage.getItem('$user')).TomcatUrl;
	$.init();
	$.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	
	function getDetailData(id){
		//parr 病区Id^开始日期^结束日期^论文题()
		var pdict = {'id':id};
		//console.log(id + ' ' + method)
		var paramDict = {'method':method,'params':JSON.stringify(pdict),'type':'RecMethod'}
		$.DHCWebService(paramDict, function(result) {
			// console.log(JSON.stringify(result))
			if (result.msgcode != '1') {
				mui.toast(result.msg)
				return
			}
			var dataArr = result.data
			updateDetailUI(dataArr)
		}, function(errorStr) {
		 	mui.toast(errorStr)
		});
	}
	// 详情页面
	function getDetailMethod(){
		var methodStr = ''
		var keyStr = 'RowID'
		switch (pageType){
			case '调配申请':
				methodStr="web.INMPersonComm:GetTransRec"
				break;
			case '投诉备案':
				methodStr="web.INMPerSubComm:GetCriticItem"
				keyStr = 'criticRowID'
				break;
			case '职称备案':
				methodStr="web.INMPersonComm:GetDutyItem"
				keyStr = 'hireRowID'
				break;
			case '职务备案':
				methodStr="web.INMPersonComm:GetPostItem"
				keyStr = 'postRowID'
				break;
			case '资格注册备案':
				methodStr="web.INMPerSubComm:GetRegistedItem"
				break;
			case '离职备案':
				methodStr="web.INMInternComm:GetResign"
				keyStr = 'rowid'
				break;
			case '教育信息备案':
				methodStr="web.INMPersonComm:GetEduItem"
				keyStr = 'eduRowID'
				break;
			case '工作经历备案':
				methodStr="web.INMPersonComm:GetWorkItem"
				keyStr = 'workRowID'
				break;
			case '进修备案':
				methodStr="web.INMPerSubComm:GetStudyItem"
				keyStr = 'studyRowID'
				break;
			case '专科发展备案':
				methodStr="web.INMSpecialComm:GetSpecial"
				keyStr = 'rw'
				break;
			case '表扬备案':
				methodStr="web.INMPerSubComm:GetPraiseItem"
				keyStr = 'praiseRowID'
				break;
			case '社会兼职备案':
				methodStr="web.INMPerSubComm:GetSocialWorkItem"
				break;
			case '层级备案':
				methodStr="web.INMPersonComm:GetLevelItem"
				keyStr = 'levelRowID'
				break;
			default:
				break;
		}
		return {'method':methodStr,'keyStr':keyStr}
	}
	
	function updateDetailUI(dataDict){
		var applyer = ''
		var appWard = ''
		var CreateDateTime=''
		var middleHtml = ''
		var middle2Html = ''
		var statusDesc = dataDict['status']
		
		// '<li class="mui-table-view-cell"><div class="leftText">申请日期：</div><div class="rightText">'+dataDict['']+'</div></li>'+
		var html1 = '<li class="mui-table-view-cell"><div class="leftText">',html2='</div><div class="rightText">',html3='</div></li>'
		switch (pageType){
			case '调配申请':
				statusDesc = dataDict['AppStatus']
				appWard = dataDict['AppWard']
				applyer = dataDict['AppNur']
				middleHtml =html1 + '申请日期：'	+ html2 + dataDict['AppDate'] 				+ html3 +
							html1 + '申请人数：' 	+ html2 + dataDict['AppNurCount'] 		+ html3 +
							html1 + '计划开始日期：' 	+ html2 + dataDict['PlanStDate'] 		+ html3 +
							html1 + '计划结束日期：' 	+ html2 + dataDict['PlanEndDate'] 		+ html3 +
							html1 + '天数：' 		+ html2 + dataDict['PlanDays'] 			+ html3 +
							html1 + '申请原因：' 	+ html2 + dataDict['AppReason'] 		+ html3 +
							html1 + '护士条件：' 	+ html2 + dataDict['AppNurCondition'] 	+ html3 +
							html1 + '薪酬说明：' 	+ html2 + dataDict['AppSalary'] 		+ html3 +
							html1 + '备注：' 		+ html2 + dataDict['AppRemark'] 		+ html3 
				break;
			case '投诉备案':
				statusDesc = dataDict['criticStatus']
				middleHtml =html1 + '来源：' 	+ html2 + preData['criticFrom'] 		+ html3 +
							html1 + '发生时间：' + html2 + dataDict['criticDate'] 		+ html3 +
							html1 + '反馈人：' 	+ html2 + dataDict['criticBack'] 		+ html3 +
							html1 + '处理结果：' + html2 + dataDict['criticDeal'] 		+ html3 +
							html1 + '事件描述：' + html2 + dataDict['criticDesc'] 		+ html3 +
							html1 + '记录人：' 	+ html2 + dataDict['criticRecorder1'] 	+ html3 +
							html1 + '记录时间：' + html2 + dataDict['criticRecordDate1'] + html3 +
							html1 + '整改效果：' + html2 + dataDict['criticRectifEffect'] 		+ html3+
							html1 + '附件：' 	+ html2 + getDetailFileHtml(dataDict['criticFile'],1,TomcatUrl) 	+ html3 ;
					
				middle2Html=html1 + '整改措施：' + html2 + dataDict['criticRectifAction'] + html3 +
							html1 + '整改结果：' + html2 + dataDict['criticRectifEffect'] + html3 +
							html1 + '记录人：' 	+ html2 + dataDict['criticRecorder2'] + html3 +
							html1 + '记录时间：' + html2 + dataDict['criticRecordDate2'] + html3 
				break;
			case '职称备案':
				statusDesc = dataDict['status']
				middleHtml =html1 + '聘任职称：' 	+ html2 + dataDict['HireDutyDesc'] 		+ html3 +
							html1 + '聘任开始日期：' 	+ html2 + dataDict['HireStDate'] 	+ html3 +
							html1 + '聘任截止日期：' 	+ html2 + dataDict['HireEndDate'] 	+ html3 +
							html1 + '专业技术职称：' 	+ html2 + dataDict['MajorDutyDesc'] 	+ html3 +
							html1 + '取得时间：' 	+ html2 + dataDict['MajorDutyDate'] + html3 +
							html1 + '取得时间：' 	+ html2 + dataDict['HireRemark'] 	+ html3 +
							html1 + '附件：' 		+ html2 + getDetailFileHtml(dataDict['hirFile'],1,TomcatUrl) + html3 ;
				break;
			case '职务备案':
				statusDesc = dataDict['status']
				middleHtml =html1 + '职务名称：' 	+ html2 + dataDict['PostDutyDesc']	+ html3 +
							html1 + '任命开始日期：' 	+ html2 + dataDict['PostStDate'] 	+ html3 +
							html1 + '任命截止日期：' 	+ html2 + dataDict['PostEndDate'] 	+ html3 +
							html1 + '备注：' 		+ html2 + dataDict['PostRemark'] 	+ html3 
				break;
			case '资格注册备案':
				statusDesc = dataDict['RegistedStatus']
				middleHtml =html1 + '注册日期：' + html2 + dataDict['RegistedDate'] 			+ html3 +
							html1 + '附件：' 	+ html2 + getDetailFileHtml(dataDict['registerFile'],1,TomcatUrl) 	+ html3 
				break;
			case '离职备案':
				statusDesc = dataDict['resignStatuDesc']
				middleHtml =html1 + '离职日期：' + html2 + dataDict['ResignDate'] + html3 +
							html1 + '离职原因：' + html2 + dataDict['ResignReasonDesc'] + html3 
				break;
			case '教育信息备案':
				statusDesc = dataDict['status']
				middleHtml =html1 + '入学日期：' + html2 + dataDict['eduStDate'] 	+ html3 +
							html1 + '毕业日期：' + html2 + dataDict['eduEndDate'] 	+ html3 +
							html1 + '教育性质：' + html2 + dataDict['eduRadio'] 		+ html3 +
							html1 + '毕业院校：' + html2 + dataDict['eduSchool'] 	+ html3 +
							html1 + '专业：' 	+ html2 + dataDict['eduProfession'] + html3 +
							html1 + '学历：' 	+ html2 + dataDict['eduAcademic'] 	+ html3 +
							html1 + '学位：' 	+ html2 + dataDict['eduDegree'] 	+ html3 +
							html1 + '学位日期：' + html2 + dataDict['eduDegreeDate'] + html3 +
							html1 + '附件：' 	+ html2 + getDetailFileHtml(dataDict['eduFile'],1,TomcatUrl) 	+ html3 
				break;
			case '工作经历备案':
				if(dataDict['worktype'] == 'T'){
					statusDesc = dataDict['workStatus']
					middleHtml =html1 + '开始日期：' + html2 + dataDict['workStDate'] 	+ html3 +
								html1 + '结束日期：' + html2 + dataDict['workEndDate'] 	+ html3 +
								html1 + '工作单位：' + html2 + dataDict['workUnit'] 		+ html3 +
								html1 + '担任职务：' + html2 + dataDict['workPost'] 	+ html3 +
								html1 + '岗位职称：' + html2 + dataDict['workDuty'] 	+ html3 +
								html1 + '备注：' 	+ html2 + dataDict['workRemark'] 	+ html3
				}else{
					statusDesc = dataDict['WorkStatus']
					middleHtml =html1 + '开始日期：' + html2 + dataDict['WorkStDate'] 	+ html3 +
								html1 + '结束日期：' + html2 + dataDict['WorkEndDate'] 	+ html3 +
								html1 + '工作单位：' + html2 + dataDict['WorkUnit'] 		+ html3 +
								html1 + '担任职务：' + html2 + dataDict['WorkPostDesc'] 	+ html3 +
								html1 + '岗位职称：' + html2 + dataDict['WorkDutyDesc'] 	+ html3 +
								html1 + '备注：' 	+ html2 + dataDict['WorkRemark'] 	+ html3
				}
				break;
			case '进修备案':
				statusDesc = dataDict['studyStatus']
				middleHtml =html1 + '培训专业：' + html2 + dataDict['studyProfession'] + html3 +
							html1 + '培训医院：' + html2 + dataDict['studyHospital'] + html3 +
							html1 + '开始日期：' + html2 + dataDict['studyStDate'] + html3 +
							html1 + '结束日期：' + html2 + dataDict['studyEndDate'] + html3 +
							html1 + '期限(天)：' + html2 + dataDict['studyLength'] + html3
				break;
			case '专科发展备案':
				statusDesc = dataDict['SpecialStatusDesc']
				applyer = dataDict['SpecialPerName']
				CreateDateTime = dataDict['CreateDate'] +' '+dataDict['CreateTime']
				middleHtml =html1 + '专科认证单位：' 	+ html2 + dataDict['SpecialAuthDesc'] + html3 +
							html1 + '专科证书：' 	+ html2 + dataDict['SpecialTypeDesc'] + html3 +
							html1 + '专科护士：' 	+ html2 + dataDict['SpecialNurTypeDesc'] + html3 +
							html1 + '取得日期：' 	+ html2 + dataDict['SpecialAuthDate'] + html3 +
							html1 + '附件：' 		+ html2 + getDetailFileHtml(dataDict['SpecialCertificate'],1,TomcatUrl) + html3 
				break;
			case '表扬备案':
				statusDesc = dataDict['praiseStatus']
				applyer = dataDict['praiseRecorder']
				middleHtml =html1 + '表扬来源：' + html2 + dataDict['praiseFromDesc'] + html3 +
							html1 + '发生时间：' + html2 + dataDict['praiseDate'] + html3 +
							html1 + '事件描述：' + html2 + dataDict['praiseDesc'] + html3 +
							html1 + '附件：' 	+ html2 + getDetailFileHtml(dataDict['praiseFile'],1,TomcatUrl) + html3 +
							html1 + '记录人：' 	+ html2 + dataDict['praiseRecorder'] + html3 +
							html1 + '记录时间：' + html2 + dataDict['praiseRecordDate'] + html3
				break;
			case '社会兼职备案':
				statusDesc = dataDict['workStatus']
				middleHtml =html1 + '兼职类型：' + html2 + dataDict['workTypeDesc'] 		+ html3 +
							html1 + '兼职机构：' + html2 + dataDict['workUnitDesc'] 		+ html3 +
							html1 + '担任职务：' + html2 + dataDict['workPost'] 			+ html3 +
							html1 + '开始日期：' + html2 + dataDict['workStDate'] 		+ html3 +
							html1 + '结束日期：' + html2 + dataDict['workEndDate'] 		+ html3 +
							html1 + '兼职级别：' + html2 + dataDict['workLevelDesc'] 	+ html3 +
							html1 + '级别明细：' + html2 + dataDict['workLevelRemark'] 	+ html3 +
							html1 + '备注：' 	+ html2 + dataDict['workRemark'] 		+ html3 
				break;
			case '层级备案':
				statusDesc = dataDict['status']
				middleHtml =html1 + '层级：' 	+ html2 + dataDict['nurLevel'] + html3 +
							html1 + '晋升日期：' + html2 + dataDict['levelDate'] + html3 +
							html1 + '系数：' 	+ html2 + dataDict['levelFactor'] + html3 +
							html1 + '备注：' 	+ html2 + dataDict['levelRemark'] + html3 
				break;
			case '科研履历':
				statusDesc = dataDict['awardStatus']
				middleHtml =html1 + '科研成果：' 	+ html2 + dataDict['awardResult'] + html3 +
							html1 + '获奖名称：' + html2 + dataDict['awardTitle'] + html3 +
							html1 + '专利名称：' 	+ html2 + dataDict['awardPatent'] + html3 +
							html1 + '专利类型：' 	+ html2 + dataDict['awardPatType'] + html3 +
							html1 + '出版社：' 	+ html2 + dataDict['awardPublic'] + html3 +
							html1 + '版号页码：' 	+ html2 + dataDict['awardPage'] + html3 +
							html1 + '奖项等级：' 	+ html2 + dataDict['awardScore'] + html3 +
							html1 + '获奖日期：' 	+ html2 + dataDict['awardDate'] + html3 +
							html1 + '获奖排序：' 	+ html2 + dataDict['awardRank'] + html3 
				break;
			default:
				break;
		}
		$('#middleUL')[0].innerHTML = middleHtml
		if (middle2Html != '') {
			var ul = document.createElement('ul')
			ul.setAttribute('class','mui-table-view')
			ul.innerHTML = middle2Html;
		}
		var statusDict = getStatusDict(statusDesc);
		
		$('#applyer')[0].innerHTML = perInfo['loginName'] + ' ' + pageType
		$('#appLoc')[0].innerHTML = '申请科室：' + appWard
		$('#appDate')[0].innerHTML = statusDict.commitText + '时间：'+CreateDateTime
		switch (pageType){
			case "职称备案":
			case "职务备案":
			case "资格注册备案":
			case "离职备案":
			case "教育信息备案":
			case "投诉备案":
			case "表扬备案":
				$('#appLoc')[0].style.display = 'none'
				$('#appDate')[0].style.display = 'none'
				break;
			default:
				break;
		}
		
		var statusIcon = statusDict['statusIcon']
		if (statusIcon == '') {
			$('#statusIcon')[0].innerHTML = statusDesc
		}else{
			$('#statusIcon')[0].innerHTML = '<div class="nurfont '+statusIcon+'"></div>'
		}
		
		var AuditOpinion = dealStringUndefind(dataDict['AuditOpinion'])
		if (pageType == '离职备案') {
			AuditOpinion = dealStringUndefind(dataDict['ResignOpinion'])
		}
		var processHtml = '<li class="mui-table-view-cell '+statusDict.approveClass+'">'+
				'<div class="processIcon"><div class="nurfont '+statusDict.approveIcon+'"></div></div>'+
				'<div class="oneline">'+
					'<div class="dealName mui-ellipsis">'+ dealStringUndefind(dataDict['AuditorName'])+'  '+statusDict.approveText+'</div>'+
					'<div class="dealDate">'+dealStringUndefind(dataDict['AuditDate'])+' '+dealStringUndefind(dataDict['AuditTime'])+'</div>'+
				'</div>'+
				'<div class="dealLoc mui-ellipsis">'+AuditOpinion+'</div>'+
			'</li>'
		if (preData['worktype'] != 'T') {
			processHtml += '<li class="mui-table-view-cell">'+
				'<div class="processIcon"><div class="nurfont nur-nocheck"></div></div>'+
				'<div class="oneline">'+
					'<div class="dealName mui-ellipsis">'+ dealStringUndefind(dataDict['CreatorName'])+'  '+statusDict.commitText+'</div>'+
					'<div class="dealDate">'+dealStringUndefind(dataDict['CreateDate']) + ' '+ dealStringUndefind(dataDict['CreateTime'])+'</div>'+
				'</div>'+
				'<div class="dealLoc mui-ellipsis">'+appWard+'</div>'+
			'</li>'
		}
		$('#processUL')[0].innerHTML = processHtml
		setupDetailFileTap('middleUL')
	}
	
	
	function getStatusDict(statusDesc){
		var statusIcon = ''
		var approveClass = ''
		var approveText = ''
		var approveIcon = ''
		var commitText = '提交'
		switch (statusDesc){
			case '保存':
			case '已保存':
			case '未提交':
				commitText = '保存'
				statusIcon = 'nur-statusS'
				approveClass = ''
				approveText = '待提交'
				approveIcon = 'nur-nocheck'
				break;
			case '提交':
			case '已提交':
			case '待审核':
				statusIcon = 'nur-statusR'
				approveClass = 'dealing';
				approveText = '审核中';
				approveIcon = 'nur-zanting'
				break;
			case '审核':
			case '已审核':
			case '审核通过':
			case '护理部已审核':
				statusIcon = 'nur-statusA'
				approveClass = 'pass';
				approveText = '审核通过';
				approveIcon = 'nur-correct'
				break;
			case '驳回':
				statusIcon = 'nur-statusB'
				approveText = '审核不通过'
				approveClass = 'refuse'
				approveIcon = 'nur-error'
				break;
			case '提请护理部审核':
				approveClass = 'dealing';
				approveText = '提请护理部审核';
				approveIcon = 'nur-zanting'
				break;
			default:
				break;
		}
		return {'statusIcon':statusIcon,'approveClass':approveClass,'approveText':approveText,'approveIcon':approveIcon,'commitText':commitText};
	}
	function baseSetup(){
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui.previewImage();
		perInfo = app.getState()
		var self = plus.webview.currentWebview()
		preData = self.data
		// console.log(JSON.stringify(preData));
		pageType = self.pageType
		var dict = getDetailMethod()
		var idKey = dict['keyStr']
		method = dict['method']
		var id = preData[idKey]
		if (preData['worktype'] == 'T' || '教育信息备案' == pageType || '层级备案' == pageType || '科研履历' == pageType) {
			updateDetailUI(preData)
		}else{
			getDetailData(id);
		}
		
	}
	function dealStringUndefind(str){
		return str==undefined?'':str
	}
	
})(mui)
/*状态
职称、职务备案 N:未提交 Y:提交 A:已审核 B:驳回
表扬备案 N:保存 S：提交 A：审核 B：驳回
投诉备案 N:保存 Y：提交 A：审核 B：驳回

*/